Replace broken, overly clever implementation with one that works.
authorSøren Sandmann <sandmann@redhat.com>
Sat, 23 Oct 2004 20:10:40 +0000 (20:10 +0000)
committerSøren Sandmann Pedersen <ssp@src.gnome.org>
Sat, 23 Oct 2004 20:10:40 +0000 (20:10 +0000)
Sat Oct 23 16:07:46 2004  Søren Sandmann  <sandmann@redhat.com>

* gtk/gtksequence.c (_gtk_sequence_swap): Replace broken, overly
clever implementation with one that works.

* gtk/gtkliststore.c (gtk_list_store_swap): emit "rows_reordered"
instead of "changed" twice.

Bug 153479

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtkliststore.c
gtk/gtksequence.c

index 6a5a3a0e0daa4a967657da955a8e88a0b338a183..36be7ee561ea1b205e81b2e0eaa538ad97bb6377 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Sat Oct 23 16:07:46 2004  Søren Sandmann  <sandmann@redhat.com>
+
+       * gtk/gtksequence.c (_gtk_sequence_swap): Replace broken, overly
+       clever implementation with one that works.
+       
+       * gtk/gtkliststore.c (gtk_list_store_swap): emit "rows_reordered"
+       instead of "changed" twice.
+
+       Bug 153479
+
 Sat Oct 23 15:17:55 2004  Søren Sandmann  <sandmann@redhat.com>
 
        * gtk/gtkmenutoolbutton.c (button_state_changed_cb): Remove check
index 6a5a3a0e0daa4a967657da955a8e88a0b338a183..36be7ee561ea1b205e81b2e0eaa538ad97bb6377 100644 (file)
@@ -1,3 +1,13 @@
+Sat Oct 23 16:07:46 2004  Søren Sandmann  <sandmann@redhat.com>
+
+       * gtk/gtksequence.c (_gtk_sequence_swap): Replace broken, overly
+       clever implementation with one that works.
+       
+       * gtk/gtkliststore.c (gtk_list_store_swap): emit "rows_reordered"
+       instead of "changed" twice.
+
+       Bug 153479
+
 Sat Oct 23 15:17:55 2004  Søren Sandmann  <sandmann@redhat.com>
 
        * gtk/gtkmenutoolbutton.c (button_state_changed_cb): Remove check
index 6a5a3a0e0daa4a967657da955a8e88a0b338a183..36be7ee561ea1b205e81b2e0eaa538ad97bb6377 100644 (file)
@@ -1,3 +1,13 @@
+Sat Oct 23 16:07:46 2004  Søren Sandmann  <sandmann@redhat.com>
+
+       * gtk/gtksequence.c (_gtk_sequence_swap): Replace broken, overly
+       clever implementation with one that works.
+       
+       * gtk/gtkliststore.c (gtk_list_store_swap): emit "rows_reordered"
+       instead of "changed" twice.
+
+       Bug 153479
+
 Sat Oct 23 15:17:55 2004  Søren Sandmann  <sandmann@redhat.com>
 
        * gtk/gtkmenutoolbutton.c (button_state_changed_cb): Remove check
index 6a5a3a0e0daa4a967657da955a8e88a0b338a183..36be7ee561ea1b205e81b2e0eaa538ad97bb6377 100644 (file)
@@ -1,3 +1,13 @@
+Sat Oct 23 16:07:46 2004  Søren Sandmann  <sandmann@redhat.com>
+
+       * gtk/gtksequence.c (_gtk_sequence_swap): Replace broken, overly
+       clever implementation with one that works.
+       
+       * gtk/gtkliststore.c (gtk_list_store_swap): emit "rows_reordered"
+       instead of "changed" twice.
+
+       Bug 153479
+
 Sat Oct 23 15:17:55 2004  Søren Sandmann  <sandmann@redhat.com>
 
        * gtk/gtkmenutoolbutton.c (button_state_changed_cb): Remove check
index b4dc32031a6b37671d0b250d09c8366dc3491933..9e9d48cf9443e93c498c598e2d50fed1ba517a28 100644 (file)
@@ -1426,43 +1426,6 @@ gtk_list_store_reorder (GtkListStore *store,
   gtk_tree_path_free (path);
 }
 
-/**
- * gtk_list_store_swap:
- * @store: A #GtkListStore.
- * @a: A #GtkTreeIter.
- * @b: Another #GtkTreeIter.
- *
- * Swaps @a and @b in @store. Note that this function only works with
- * unsorted stores.
- *
- * Since: 2.2
- **/
-void
-gtk_list_store_swap (GtkListStore *store,
-                    GtkTreeIter  *a,
-                    GtkTreeIter  *b)
-{
-  GtkTreePath *path;
-
-  g_return_if_fail (GTK_IS_LIST_STORE (store));
-  g_return_if_fail (!GTK_LIST_STORE_IS_SORTED (store));
-  g_return_if_fail (VALID_ITER (a, store));
-  g_return_if_fail (VALID_ITER (b, store));
-
-  if (a->user_data == b->user_data)
-    return;
-
-  _gtk_sequence_swap (a->user_data, b->user_data);
-  
-  /* emit signal */
-  path = gtk_tree_path_new ();
-  
-  gtk_tree_model_row_changed (GTK_TREE_MODEL (store), path, a);
-  gtk_tree_model_row_changed (GTK_TREE_MODEL (store), path, b);
-  
-  gtk_tree_path_free (path);
-}
-
 static GHashTable *
 save_positions (GtkSequence *seq)
 {
@@ -1502,6 +1465,48 @@ generate_order (GtkSequence *seq,
   return order;
 }
 
+/**
+ * gtk_list_store_swap:
+ * @store: A #GtkListStore.
+ * @a: A #GtkTreeIter.
+ * @b: Another #GtkTreeIter.
+ *
+ * Swaps @a and @b in @store. Note that this function only works with
+ * unsorted stores.
+ *
+ * Since: 2.2
+ **/
+void
+gtk_list_store_swap (GtkListStore *store,
+                    GtkTreeIter  *a,
+                    GtkTreeIter  *b)
+{
+  GHashTable *old_positions;
+  gint *order;
+  GtkTreePath *path;
+
+  g_return_if_fail (GTK_IS_LIST_STORE (store));
+  g_return_if_fail (!GTK_LIST_STORE_IS_SORTED (store));
+  g_return_if_fail (VALID_ITER (a, store));
+  g_return_if_fail (VALID_ITER (b, store));
+
+  if (a->user_data == b->user_data)
+    return;
+
+  old_positions = save_positions (store->seq);
+  
+  _gtk_sequence_swap (a->user_data, b->user_data);
+
+  order = generate_order (store->seq, old_positions);
+  path = gtk_tree_path_new ();
+  
+  gtk_tree_model_rows_reordered (GTK_TREE_MODEL (store),
+                                path, NULL, order);
+
+  gtk_tree_path_free (path);
+  g_free (order);
+}
+
 static void
 gtk_list_store_move_to (GtkListStore *store,
                        GtkTreeIter  *iter,
index 61f0aefb5d5baa4baf8fc2845508fbd9dd36259c..8953c0c0b24ec8fe3bbb8cad46666e109eb5fae1 100644 (file)
@@ -1070,21 +1070,35 @@ void
 _gtk_sequence_swap (GtkSequencePtr a,
                    GtkSequencePtr b)
 {
-  GtkSequenceNode temp;
-  gpointer temp_data;
+  GtkSequenceNode *leftmost, *rightmost, *rightmost_next;
+  int a_pos, b_pos;
   
   g_return_if_fail (!_gtk_sequence_ptr_is_end (a));
   g_return_if_fail (!_gtk_sequence_ptr_is_end (b));
+
+  if (a == b)
+      return;
+
+  a_pos = _gtk_sequence_ptr_get_position (a);
+  b_pos = _gtk_sequence_ptr_get_position (b);
+
+  if (a_pos > b_pos)
+    {
+      leftmost = b;
+      rightmost = a;
+    }
+  else
+    {
+      leftmost = a;
+      rightmost = b;
+    }
+
+  rightmost_next = _gtk_sequence_node_next (rightmost);
+
+  /* Situation now:  ..., leftmost, ......., rightmost, rightmost_next, ... */
   
-  /* swap contents of the nodes */
-  temp = *a;
-  *a = *b;
-  *b = temp;
-  
-  /* swap data back */
-  temp_data = a->data;
-  a->data = b->data;
-  b->data = temp_data;
+  _gtk_sequence_move (rightmost, leftmost);
+  _gtk_sequence_move (leftmost, rightmost_next);
 }
 
 void